/*
RNAvigator is a tool for visualizing secondary structure of RNA
Copyright 2012 Elias La Cour & Peter Bertelsen

This file is part of RNAvigator.

RNAvigator is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

RNAvigator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with RNAvigator.  If not, see <http://www.gnu.org/licenses/>.
*/

package rnavigator.model;

import java.util.HashMap;
import java.util.LinkedList;

/**
 *
 * @author Elias la Cour & Peter Bertelsen
 */
public class InputTesting {

    /**
     * Creates a long sequence of nucleotides
     * @return Returns a Structure
     */
    private boolean debug = false;

    /**@standardizeInput()
     * method to make sure all lengths, characters etc are valid,
     * and to create a new structure object
     */
    public void validateInput(Structure structure) {
        if (structure.getBaseSequence().length != structure.getDotSequence().length) {
            System.err.println("Mismatch between BaseSequence l:" + structure.getBaseSequence().length
                    + " and DotSequence l: " + structure.getDotSequence());
            System.exit(1);
        }
    }

    /**
     * for standardizing different fileformats to the same readable structure
     */
    public void standardizeInput() {
    }

    /**
     * a small test input containing sequence as well as structure + pseudoknots
     * @return Returns a Structure
     */
    public Structure smallInput() {
        String inSeq =         "UUAGCUCGCCAGUUAGCGAGGUCUGUCCCCACACGACAGAUAAUCGGGUGCAACUCCCGCCCCUUUUCCGAGGGUCAUCGGAACCA";
        String inDotSequence = "::::(((((::::::))))):((((((:::::::))))))::::((((:::::::))))(((:::[[[[[[))):::]]]]]]:::";
        String[] sequence = new String[inSeq.length()];
        String[] dotSequence = new String[inDotSequence.length()];
        for (int i = 0; i < inSeq.length(); i++) {
            sequence[i] = inSeq.substring(i, i + 1);
            dotSequence[i] = inDotSequence.substring(i, i + 1);
        }
        Structure s = new Structure();
        s.setDotSequence(dotSequence);
        s.setBaseSequence(sequence);

        if (debug) {
            System.out.print("length of basesequence is " + s.getBaseSequence().length + "\n");
            for (String seq : s.getBaseSequence()) {
                System.out.print(seq);
            }
            System.out.println();
        }
        return s;
    }
    public Structure miniInput() {
        String inSeq =         "UUAGCUCGCCAGUUAGCGAGG";
        String inDotSequence = "::::(((((::::::))))):";
        String[] sequence = new String[inSeq.length()];
        String[] dotSequence = new String[inDotSequence.length()];
        for (int i = 0; i < inSeq.length(); i++) {
            sequence[i] = inSeq.substring(i, i + 1);
            dotSequence[i] = inDotSequence.substring(i, i + 1);
        }
        Structure s = new Structure();
        s.setDotSequence(dotSequence);
        s.setBaseSequence(sequence);

        if (debug) {
            System.out.print("length of basesequence is " + s.getBaseSequence().length + "\n");
            for (String seq : s.getBaseSequence()) {
                System.out.print(seq);
            }
            System.out.println();
        }
        return s;
    }

    public Structure smallInputNoPseudo() {
        String inSeq = "UUAGCUCGCCAGUUAGCGAGGUCUGUCCCCACACGACAGAUAAUCGGGUGCAACUCCCGCCCCUUUUCCGAGGGUCAUCGGAACCA";
        String inDotSequence = "::::(((((::::::))))):((((((:::::::))))))::::((((:::::::))))(((:::::::::)))::::::::::::";
        String[] sequence = new String[inSeq.length()];
        String[] dotSequence = new String[inDotSequence.length()];
        for (int i = 0; i < inSeq.length(); i++) {
            sequence[i] = inSeq.substring(i, i + 1);
            dotSequence[i] = inDotSequence.substring(i, i + 1);
        }
        Structure s = new Structure();
        s.setDotSequence(dotSequence);
        s.setBaseSequence(sequence);

        if (debug) {
            System.out.print("length of basesequence is " + s.getBaseSequence().length + "\n");
            for (String seq : s.getBaseSequence()) {
                System.out.print(seq);
            }
            System.out.println();
        }
        return s;
    }

    public Structure verySmallInput() {
        String[] sequence = {"C", "C", "C", "A", "A", "A", "A", "A", "G", "G", "G"};
        String[] dotSequence = {"(", "(", "(", ":", ":", ":", ":", ":", ")", ")", ")"};
        Structure s = new Structure();
        s.setDotSequence(dotSequence);
        s.setBaseSequence(sequence);

        if (debug) {
            System.out.print("length of basesequence is " + s.getBaseSequence().length + "\n");
            for (String seq : s.getBaseSequence()) {
                System.out.print(seq);
            }
            System.out.println();
        }
        return s;
    }

    public Structure testcase10k() {
        String[] sequence = new String[10000];
        //for (String str : sequence) {
        for (int i = 0; i < sequence.length; i++) {
            String str = "A";
            sequence[i] = str;
        }

        String[] dotSequence = new String[10000];
        for (int j = 0; j < dotSequence.length; j++) {
            String d = ":";
            dotSequence[j] = d;
        }
        for(int k = 0; k<2500;k++){
            int a = (int)(Math.random()*9999)+1;
            int b = (int)(Math.random()*9999)+1;
            if(dotSequence[a].equals(":") && dotSequence[b].equals(":")){
                dotSequence[a]="(";
                dotSequence[b]=")";
            }
        }

        Structure s = new Structure();
        s.setDotSequence(dotSequence);
        System.out.println("dots:");
        for(String strg : dotSequence){
            System.out.print(strg);
        }
        s.setBaseSequence(sequence);
        if (debug) {
            System.out.print("length of basesequence is " + s.getBaseSequence().length + "\n");
            for (String seq : s.getBaseSequence()) {
                System.out.print(seq);
            }
            System.out.println();
        }
        return s;
    }

    /**
     * @param debug the debug to set
     */
    public void setDebug(boolean debug) {
        this.debug = debug;
    }
}
